/**
 * @file kilb.h
 * @author lcz (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2022-10-20
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#ifndef KILB_H
#define KILB_H

// define string operation function

void kernel_strcpy(char *dest, const char *src);
void kernel_strncpy(char *dest, const char *src, int size);
int kernel_strncmp(const char *s1, const char *s2, int size);

int kernel_strlen(const char *str);

int kernel_memcpy(void *dest, void *src, int size);
int kernel_memset(void *dest, uint8_t v, int size);
int kernel_memcmp(void *d1, void *d2, int size);

// #define ERLEASE 0
// 手工定义一下宏后断言失效，像(void) 0 这样的代码只有被编译器优化掉的份！！！当然也可在顶层CMake文件中添加该宏
#ifndef ERLEASE
#define ASSERT(expr) \
    if (!(expr))     \
    pannic(__FILE__, __LINE__, __func__, #expr);
#else
#define ASSERT(expr) (void) 0 ;
#endif

void pannic(const char *file, int line, const char *func, const char *cond);

// 2**n
// size =0x1010 bound  0x1000
// bound -1 =0x0fff
// ~(bound-1)=0xffff1000
// ox1010 & 0xffff1000 =0x1000
// 向下取整
static inline uint32_t down2(uint32_t size, uint32_t bound)
{
    return size & ~(bound - 1);
}

// 相当于向上取整
static inline uint32_t up2(uint32_t size, uint32_t bound)
{
    return (size + bound - 1) & ~(bound - 1);
}

int strings_count(char **start);
char *get_file_name(const char *name);

#endif

